'use strict';

let express = require('express');
let app = express();
let verifyToken = require('./utils/verifyToken.js');

// 解析 xml数据
let bodyParser = require('body-parser');
require('body-parser-xml')(bodyParser);
app.use(bodyParser.xml());

app.use(express.json()) 
app.use(express.urlencoded({ extended: true })) 

// 设置跨域
app.use((req,res,next)=>{
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Cache-Control,Authorization,token,crossDomain, Accept,X-Requested-With, If-Modified-Since");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    // res.header("Access-Control-Allow-Credentials", true);
    res.setHeader('cache-control','no-store')
    next();
})

// 校验 token 有效性 
app.use(verifyToken); 

var router = require('./router.js');

// 挂载路由中间件
app.use('/', router);

app.listen(8000, () => {
    console.log('猫眼api服务已启动,地址：http://127.0.0.1:8000');
});
